package com.konsung.ksdc.manager.addr;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.konsung.ksdc.R;
import com.konsung.ksdc.bean.AddrUltimateBean;
import com.konsung.ksdc.common.utils.ActivityCollector;
import com.konsung.ksdc.manager.appmain.BaseActivity;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/5/16 0016.
 */
public class DistrictStep1 extends BaseActivity {
    public static final String CITY_DATAS = "city_datas";
    public static final String PROVINCE_NAME = "city_name";
    public static final String PROVINCE_CODE = "city_code";
    @Bind(R.id.rl_back)
    RelativeLayout rlBack;
    @Bind(R.id.tab_tv_title)
    TextView tabTvTitle;
    @Bind(R.id.tv_save)
    TextView tvSave;
    @Bind(R.id.rl_title_container)
    RelativeLayout rlTitleContainer;
    @Bind(R.id.lv_area)
    ListView lvProvince;
    private ArrayList<AddrUltimateBean> datas;

    @Override
    protected String activityDesc() {
        return getString(R.string.page_choose_district1);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_district_step);
        ButterKnife.bind(this);
        ActivityCollector.addActivity(DistrictStep1.this);
        initData();
        initView();
    }

    /**
     * init view
     */
    private void initView() {
        tabTvTitle.setText(R.string.title_addr_step1);
        lvProvince.setAdapter(new DistrictProvinceAdapter(datas));
        rlBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ActivityCollector.removeActivity(DistrictStep1.this);
                finish();
            }
        });
        lvProvince.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int
                    position, long id) {
                Intent intent = new Intent(DistrictStep1.this, DistrictStep2
                        .class);
                AddrUltimateBean addrUltimateBean = datas.get(position);
                intent.putExtra(CITY_DATAS, addrUltimateBean);
                intent.putExtra(PROVINCE_NAME, addrUltimateBean.getAreaName());
                intent.putExtra(PROVINCE_CODE, addrUltimateBean.getAreaId());
                startActivity(intent);
            }
        });
    }

    /**
     * init data
     */
    private void initData() {
        datas = getIntent().getParcelableArrayListExtra(CreateAddrActivity
                .DISTRICT_DATA);
    }
}
